package org.example.demo4.controller.freight;

import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.example.demo4.service.SysDeptService;
import org.example.demo4.model.SysDeptEntity;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/sysDept")
@Tag(name = "部门")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    /**
     * 添加
     *
     * @param sysDept
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    @Operation(summary = "添加")
    @Parameters(value = {
            @Parameter(name = "deptId", description = ""),

            @Parameter(name = "parentId", description = ""),

            @Parameter(name = "ancestors", description = ""),

            @Parameter(name = "deptName", description = ""),

            @Parameter(name = "orderNum", description = ""),

            @Parameter(name = "leader", description = ""),

            @Parameter(name = "phone", description = ""),

            @Parameter(name = "email", description = ""),

            @Parameter(name = "status", description = ""),

            @Parameter(name = "delFlag", description = ""),

            @Parameter(name = "createBy", description = ""),

            @Parameter(name = "createTime", description = ""),

            @Parameter(name = "updateBy", description = ""),

            @Parameter(name = "updateTime", description = ""),

            @Parameter(name = "sapCode", description = "")
    })
    public boolean save(@RequestBody SysDeptEntity sysDept) {
        return sysDeptService.save(sysDept);
    }


    /**
     * 根据主键删除
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    @Operation(summary = "根据主键删除")
    @Parameters(value = {
            @Parameter(name = "deptId", description = "", required = true)
    })
    public boolean remove(@PathVariable Serializable id) {
        return sysDeptService.removeById(id);
    }


    /**
     * 根据主键更新
     *
     * @param sysDept
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    @Operation(summary = "根据主键更新")
    @Parameters(value = {
            @Parameter(name = "deptId", description = "", required = true),

            @Parameter(name = "parentId", description = ""),

            @Parameter(name = "ancestors", description = ""),

            @Parameter(name = "deptName", description = ""),

            @Parameter(name = "orderNum", description = ""),

            @Parameter(name = "leader", description = ""),

            @Parameter(name = "phone", description = ""),

            @Parameter(name = "email", description = ""),

            @Parameter(name = "status", description = ""),

            @Parameter(name = "delFlag", description = ""),

            @Parameter(name = "createBy", description = ""),

            @Parameter(name = "createTime", description = ""),

            @Parameter(name = "updateBy", description = ""),

            @Parameter(name = "updateTime", description = ""),

            @Parameter(name = "sapCode", description = "")
    })
    public boolean update(@RequestBody SysDeptEntity sysDept) {
        return sysDeptService.updateById(sysDept);
    }


    /**
     * 查询所有
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    @Operation(summary = "查询所有")
    public List<SysDeptEntity> list() {
        return sysDeptService.list();
    }


    /**
     * 根据主键获取详细信息。
     *
     * @param id sysDept主键
     * @return 详情
     */
    @GetMapping("/getInfo/{id}")
    @Operation(summary = "根据主键获取详细信息")
    @Parameters(value = {
            @Parameter(name = "deptId", description = "", required = true)
    })
    public SysDeptEntity getInfo(@PathVariable Serializable id) {
        return sysDeptService.getById(id);
    }


    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询")
    @Parameters(value = {
            @Parameter(name = "pageNumber", description = "页码", required = true),
            @Parameter(name = "pageSize", description = "每页大小", required = true)
    })
    public Page<SysDeptEntity> page(Page<SysDeptEntity> page) {
        return sysDeptService.page(page);
    }
}